import re

from selenium.webdriver.common.by import By

from Auto.day02.login.Login_Operation import Login_Operation


class Ttest_F_C(Login_Operation):
    def ttest_money(self,login_driver):
        self.logins(login_driver)
        login_driver.get('http://localhost:90/user/personal/toBankCard.html')
        #使用XPATH可以定位"//*[contains(text(), '默认')]"带有特定文字的元素
        h4 = login_driver.find_element(By.XPATH,"//*[contains(text(), '默认')]")
        ## 定位上一级的上一级元素（祖父级元素）
        #示例： grandparent_element = div_element.find_element(By.XPATH, "../..")

        grandparent_element = h4.find_element(By.XPATH,"../..")
        #定位祖父的兄弟元素
        ## 定位同级元素
        #示例：sibling_element = div_element.find_element(By.XPATH, "following-sibling::div")
        sibling_element = grandparent_element.find_element(By.XPATH,"following-sibling::div")
        #定位兄弟元素的第一个子元素
        ch1 = sibling_element.find_element(By.XPATH,"./h4[1]")
        #定位兄弟元素的第二个子元素
        ch2 = sibling_element.find_element(By.XPATH,"./h4[2]")
        cardnum1 = ch1.text
        print(cardnum1)
        money1 = ch2.text
        print(money1)
        # 使用正则表达式提取数字部分
        balance_match = re.search(r"\d+\.\d+", money1)

        if balance_match:
            # 将提取到的字符串转换为浮点数
            money1 = float(balance_match.group())
            print(money1)
        else:
            print("未找到账户余额")
        print(money1)
        #定位兄弟元素的第三个子元素



